import categories.CategoriesRegistry;
import org.apache.log4j.Logger;
import org.supercsv.io.CsvListReader;
import org.supercsv.prefs.CsvPreference;
import readers.CSVRowReader;

import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;

public class DGNParser extends Parser {
    private final static Logger log = Logger.getLogger(SovintelParser.class.toString());

    public DGNParser(CategoriesRegistry categoriesRegistry,
                      File inFile,
                      OutputWriters writers
    ) throws IOException {
        super(
                "DGN parser for " + inFile,
                new CSVRowReader(
                        new CsvListReader(
                                new TrimSpacesReader(new FileReader(inFile)), 
                                new CsvPreference('"', ' ', "\n")
                        ),
                        false
                ),
                writers,
                categoriesRegistry
        );
    }

    private static final SimpleDateFormat DATE_TIME_FORMAT = new SimpleDateFormat("d.MM.yy H:mm");


    protected CallRow convertToRow(List<?> values) throws ParseException {
        // "-", "PIN","DATE", "TIME", "DestNumberPrefix", "DestNumberPostfix", "Duration", "Charge2?", "Charge2?"
        return new CallRow(
                Long.parseLong((String) values.get(1)), // cust id
                DATE_TIME_FORMAT.parse(values.get(2) + " " + values.get(3)), // datetime
                Long.parseLong("10" + (String)values.get(4) + values.get(5)), // dest num
                Double.valueOf((String)values.get(6))
        );
    }
}